package com.wlf.admin.module.service;

import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wlf.admin.common.dto.ParamPage;
import com.wlf.admin.common.util.AjaxBean;
import com.wlf.admin.module.domain.PayOrder;
import com.wlf.admin.module.mapper.PayOrderMapper;
import com.wlf.admin.system.service.SysOrganService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PayOrderService extends ServiceImpl<PayOrderMapper, PayOrder> {
    @Resource
    private SysOrganService organService;

    public AjaxBean getList(PayOrder order, ParamPage paramPage) {
        Page<PayOrder> page = this.lambdaQuery()
                .eq(order.getOrganId() != null, PayOrder::getOrganId, order.getOrganId())
                .in(PayOrder::getOrganId, SpringUtil
                        .getBean(SysOrganService.class)
                        .getByIdsStr(order.getOrganIdsStr()))
                .page(paramPage.init());
        for (PayOrder record : page.getRecords()) {
            record.setOrganName(organService.get(record.getOrganId()).getName());
        }
        return AjaxBean.getOkPage(page);
    }
}
